package _3登录例子;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet("/test")
public class TestServlet extends HttpServlet{


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw = resp.getWriter();
        pw.print("其他页面<br />");

        // 得到会话
        HttpSession session = req.getSession();
        String username = (String)session.getAttribute("username");

        if(username!=null)
        {
            pw.print("欢迎光临:"+username);
            pw.print("<a href='logout'>登出</a>");
        }
        else
        {
            pw.print("欢迎光临:游客");
            pw.print("<a href='login.html'>登录</a>");
        }





    }
}